<?php

namespace App;
use Session;
use Illuminate\Database\Eloquent\Model;
use DB;
class Member_Home extends Model{
	 //前台会员中心
	 public function find($user_id){
	 	$data=DB::table('user')->where('user_id',$user_id)->first();
	 	return $data;
	 }
     
     //前台上传图片
	 public function add($arr,$user_id){
	 	$data=DB::table('user')->where('user_id',$user_id)->update($arr);
	 	return $data;
	 }

	 // //编辑
	 // public function select($user_id){
	 // 	$data=DB::table('user')->where('user_id',$user_id)->first();
	 // 	return $data;
	 // }
	 // 我的收藏获取商品id
    public function member_collect($user_id){
    	$data = DB::table("collect")->where("user_id",$user_id)->where("status","1")->get();
    	return $data;
    }
    //我的收藏在商品表中获取商品详情
    public function collect($goods_id){
        foreach ($goods_id as $val) {
            $data[] = DB::table("goods")->where("goods_id",$val)->first();
        } 
    	return $data;
    }
    //删除收藏表中的指定商品信息
    public function collect_del($goods_id){
    	$data = ["status"=>0];
    	$res = DB::table("collect")->where("collect_id",$goods_id)->update($data);
    	return $res;
    }
    //查询在收藏夹中加入购物车的商品详情
    public function buycarOnew($id){
    	$res = DB::table("goods")->select("goods_id","goods_name","goods_price")->where("goods_id",$id)->first();
    	return $res;
    }
    //在购物车表中添加数据
    public function buycar_add($data){
    	$res = DB::table("cart")->insert($data);
    	return $res;
    }
	//前台用户收货地址
     public function select($user_id){
	 	$data=DB::table('user_address')->where(['user_id'=>$user_id,'acquiescence'=>0,'status'=>0])->first();
	 	return $data;
	 }

	 //前台用户收货地址列表
     public function selects($user_id){
        $data=DB::table('user_address')->where(['user_id'=>$user_id,'status'=>0])->get();
        return $data;
     }
     //订单页面收货地址展示
     public function selectss($user_id){
	 	$datas=DB::table('user_address')->where(['user_id'=>$user_id,'status'=>0])->select('address_name','address_id','acquiescence')->get();
	 	return array_map('get_object_vars', $datas);

	 }
    public function getOne($address_id){
        $datas=DB::table('user_address')->where(['address_id'=>$address_id,'status'=>0])->get();
        return array_map('get_object_vars', $datas);
    }
    //组合订单信息查询
    public function getOnes($address_id,$user_id){
        $datas=DB::table('user_address')->where(['address_id'=>$address_id,'status'=>0,'user_id'=>$user_id])->select('address_id','user_id','shen','shi','qu','address','zipcode','mobile','address_name')->get();
        return array_map('get_object_vars', $datas);
    }
    /*
        订单页面默认显示默认收货人信息
     */
    public function getChecked($user_id){
        $datas=DB::table('user_address')->where(['user_id'=>$user_id,'acquiescence'=>1,'status'=>0])->get();
        return array_map('get_object_vars', $datas);
    }

	  //设为默认收货地址
	   public function upshow($address_id){
	 	$data=DB::table('user_address')->where('address_id',$address_id)->update(['acquiescence'=>0]);
	 	
	 	return $data;

	 }

	  public function upshow_a($address_id,$user_id){
	  	$andwhere=array(['address_id','!=',$address_id]);
	  	$where=array(['user_id','=',$user_id]);
	 	$date=DB::table('user_address')->where($andwhere,$where)->update(['acquiescence'=>1]);

	 	return $date;
	 }

     //添加查询三级联动
     public function cha(){
     	$date=DB::table('region')->where('parent_id',1)->get();
     	return $date;
     }


       public function cha_a($id){
     	$date=DB::table('region')->where('parent_id',$id)->get();
     	return $date;
     }

      //查省
      public function cha_s($shen){
     	$date=DB::table('region')->select('region_name')->where('region_id',$shen)->first();
     	return $date;
     }
       //查市
       public function cha_w($shi){
     	$date=DB::table('region')->select('region_name')->where('region_id',$shi)->first();
     	return $date;
     }
      //查区
     public function cha_e($qu){
     	$date=DB::table('region')->select('region_name')->where('region_id',$qu)->first();
     	return $date;
     }

      //添加收货地址
      public function insert($arr){
      	
     	$date=DB::table('user_address')->insert($arr);
     	return $date;
     }

     //
     public function cha_up($address_id){
     	  $data=DB::table('user_address')->where(['address_id'=>$address_id])->first();
	 	  return $data;
     }

      //修改收货地址
      public function update_save($arr,$addid){
     	  $data=DB::table('user_address')->where('address_id',$addid)->update($arr);
	 	  return $data;
     }

     //删除收货地址
     public function del($address_id){
     	  $data=DB::table('user_address')->where('address_id',$address_id)->update(['status'=>1]);
	 	  return $data;
     }


}



?>